import java.util.*;

public class charFrequency{
  
  int store = 0;
  int j = 0, length = 0, value = 0;
  char c = ' ';
  int temp;
  int[] freq = new int[40];
  int[] text = new int[200];
  char[] data = new char[200];
  Tree tree = new Tree();
  
  //Input the desired file intro the class's constructor
  public charFrequency(String str) {
    CharReader read = new CharReader(str);
    Sorting sort = new Sorting();
    
    //Stores the ASCII value of the character being read into an array.
    int i;
    for(i = 0; store != -1; i++) {
      store = read.readNextChar();
      if(store != 0)
        text[i] = store;
    }
    text = Arrays.copyOf(text, i - 1);
    read.closeFile();
    
    //Sorts the array
    sort.quickSort(text);
  }
  
  //Stores the different ASCII values intro their own array
  public void search() {
    int total = text.length; //The total amount of characters
    Object allArrays[] = new Object[50];
    int j = 0;
    int k = 0;
    //Will take each character in the text, convert it into a character, and store the same characters
    //into their own array "data" that has to be passed on before the loop starts again, or else it will be erased.
    while(j < text.length) {
      int i = 0;
      
      int temp = text[j];
      
      int count = 0;
      for(;j < text.length && text[j] == temp; j++) {
        i++;
        data[count] = (char)temp;
        count++;
      }
      data = Arrays.copyOf(data, i);
      total += data.length;
      freq[k] = data.length;
      k++;
      
      //Great place to pass on the "data" array to the tree.  

      
      data = new char[200];
    }
    freq = Arrays.copyOf(freq, k);
    Arrays.sort(freq);
    System.out.println(Arrays.toString(freq));
  }
}